package cn.yuhh.api.v1.declare;

import cn.yuhh.api.helper.ApiResponse;
import cn.yuhh.api.helper.IDataToMap;
import cn.yuhh.api.service.AbstractApiService;
import cn.yuhh.core.domain.DeclareInfo;
import cn.yuhh.core.domain.User;
import cn.yuhh.core.type.DeclareStatus;
import com.magic.spring.mongo.Mongo;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author ysw
 * @create 2020-03-15-20:49
 * @descreption 已处理工单
 **/
@Component("listHandled1.0")
public class ListHandledService extends AbstractApiService {
    @Override
    public Map service(Map request) {
        User user = Mongo.buildMongo().eq("_id", id(request)).findOne(User.class);
        List<DeclareInfo> list = Mongo.buildMongo().eq("declareStatus", DeclareStatus.end).eq("areaInfo.countyCode", user.getAreaInfo().getCountyCode()).limit(limit(request), page(request)).find(DeclareInfo.class);
        return ApiResponse.success(list, new IDataToMap<DeclareInfo>() {
            @Override
            public void dataToMap(Map map, DeclareInfo source) {
                map.put("selfId", selfId(request));
                source.list(map);
            }
        });
    }
}
